//（待完善）定义 VarDef 中加其声明变量的类型
// 		TAC中build_VarDef_TAC等变量加入符号表中需要
//      

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifndef ENUM
#define ENUM
enum Token_T
{
	tok_ID = 256,		// 标识符
	tok_INTEGER = 257,	// 整数
	tok_INT = 258,		// int
	tok_VOID = 259,		// void
	tok_CONST = 260,	// const
	tok_IF = 261,		// if
	tok_ELSE = 262,		// else
	tok_WHILE = 263,	// while
	tok_BREAK = 264,	// break
	tok_CONTINUE = 265, // continue
	tok_RETURN = 266,	// return
	tok_ADD = 267,		// +
	tok_SUB = 268,		// -
	tok_MUL = 269,		// *
	tok_DIV = 270,		// /
	tok_MODULO = 271,	// %
	tok_LESS = 272,		// <
	tok_LESSEQ = 273,	// <=
	tok_GREAT = 274,	// >
	tok_GREATEQ = 275,	// >=
	tok_NOTEQ = 276,	// !=
	tok_EQ = 277,		// ==
	tok_NOT = 278,		// !
	tok_AND = 279,		// &&
	tok_OR = 280,		// ||
	tok_ASSIGN = 281,	// =
	tok_LPAR = 282,		 // (
	tok_RPAR = 283,		 // )
	tok_LBRACKET = 284,	 // {
	tok_RBRACKET = 285,	 // }
	tok_LSQUARE = 286,	 // [
	tok_RSQUARE = 287,	 // ]
	tok_COMMA = 288,	 // ,
	tok_SEMICOLON = 289, // ;
	tok_comment = 290
};
//Non-terminator
enum Non_terminator
{
	CompUnit=291,
	Decl,
	ConstDecl,
	ConstDefs,
	BType,
	ConstDef,
	ConstExps,
	ConstInitVal,
	ConstInitVals,
	VarDecl,
	VarDecls,
	VarDef,
	InitVal,
	InitVals,
	FuncDef,
	FuncType,
	FuncFParams,
	FuncFParamss,
	FuncFParam,
	Block,
	BlockItems,
	BlockItem,
	Stmt,
	Exp,
	Cond,
	LVal,
	Exps,
	PrimaryExp,
	Number,
	UnaryExp,
	FuncRParams,
	Expss,
	Expr,//包含多种表达式
	ID = 256,		// 标识符
	INTEGER = 257,	// 整数
};
#endif

#ifndef AST
#define AST

/*
欠一分AST的详解，各个类型节点的信息
*/

typedef struct _ast ast;
typedef struct _ast *past;
struct _ast
{
	enum Non_terminator ast_ID; // enum Non_terminator + ID(256) + NUM(257)
	union astunion
	{
		int ivalue;
		char *IDentifier;
		struct ASTstruct
		{
			int t_Token1;
			int t_Token2;
			past left;
			past middle;
			past right;
			past next;

		} node;

	} Ast_union;
};

void showAst(past node, int nest);

void showToken(int Token);

char * putInNameSpace(char *ID);// 使相同字符串指向同一个内存区域

// nest 指前方几个空格
past newAstNode();//声明新的节点

past newNum(int value);//创建数字节点
void showNum(past node, int nest);//输出数字节点

past newString(char *ID);//创建字符串节点
void showString(past node, int nest);//展示字符串节点

past newCompUnit(past left, past right);//连接两个节点，left->next = right

past newConstDecl(int oper1, int oper2, past left, past right);
void showConstDecl(past node, int nest);

past newConstDefs(past left, past right);//连接多个变量两个节点，left->next = right

past newConstDef(int oper, past left, past middle, past right);// 变量定义
void showConstDef(past node, int nest);

past newConstExps(past left, past right);// 创建常量表达式节点
void showConstExps(past node, int nest);

past newConstInitVal(past left, past middle, past right);// 常量初值节点
void showConstInitVal(past node, int nest);

past newConstInitVals(past left, past right);// 连接常量初值

past newVarDecl(int oper, past left, past right);// ..
void showVarDecl(past node, int nest);

past newVarDecls(past left, past right);// ..

past newVarDef(int oper, past left, past middle, past right);// ..
void showVarDef(past node, int nest);

past newInitVal(past left, past middle, past right);// ..
void showInitVal(past node, int nest);

past newInitVals(past left, past right);// ..

past newFuncDef(int oper, past left, past middle, past right);// 函数声明
void showFuncDef(past node, int nest);

past newFuncFParams(past left, past right);

past newFuncFParamss(past left, past right);

past newFuncFParam(int oper1, int oper2, past left, past right);// 形参声明
void showFuncFParam(past node, int nest);

past newBlock(past middle);// 代码块声明
void showBlock(past node, int nest);

past newBlockItems(past left, past right);

past newStmt(int t_Token1, int t_Token2, past left, past middle, past right);
void showStmt(past node, int nest);// 语句

past newLVal(past left, past right);// 左值表达式
void showLVal(past node, int nest);

past newExps(past left, past right);// 表达式 数组
void showExps(past node, int nest);

past newNumber(past middle);// 数字声明 只有int
void showNumber(past node, int nest);

past newUnaryExp(int t_Token, past left, past right);// 一元表达式 含函数
void showUnaryExp(past node, int nest);

past newFuncRParams(past left, past right);// 实参
void showFuncRParams(past node, int nest);

past newExpss(past left, past right);// 逗号 表达式

past newExpr(int oper, past left, past right);// 加减乘除表达式
void showExpr(past node, int nest);

#endif